package com.ruoyi.web.controller.tool;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.business.base.PageParam;
import com.ruoyi.business.core.domain.DivisionsCode;
import com.ruoyi.business.core.service.DivisionsCodeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.core.JoR;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("5级地市信息表")
@RestController
@RequestMapping("/divisions")
public class DivisionsCodeController extends BaseController
{

    @Autowired
    private DivisionsCodeService service;

    @ApiOperation("查询列表")
    @GetMapping("/list/{type}")
    public TableDataInfo list(@PathVariable String type, PageParam page, DivisionsCode code)
    {

        IPage iPage = switch (type)
        {
            case "provinces" -> service.findProvincesByCode(page.b(), code);
            case "cities" -> service.findCitiesByCode(page.b(), code);
            case "areas" -> service.findAreasByCode(page.b(), code);
            case "streets" -> service.findStreetsByCode(page.b(), code);
            case "villages" -> service.findVillagesByCode(page.b(), code);
            case "all" -> service.findAllByCode(page.b(), code);
            default -> service.findByPCode(page.b(), code);
        };

        return JoR.getDataTable(iPage);
    }

    @ApiOperation("获取详细信息")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(service.findByCode(code));
    }

}
